//
//  Date+Extensions.swift
//  EasePods
//
//  Created by 易先生 on 2024/5/7.
//

import Foundation

extension Date {
    
    /// 是否是24小时时间格式
    public static var is24HourFormat: Bool {
        let dateFormat = DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: Locale.current)
        if dateFormat?.range(of: "a") == nil {
            return true
        }
        return false
    }
    
    /// 单个日期 -> 字符串
    var curDayString: String {
        if self.isToday {
            return R.string.localizable.common_calendar_today()
        }
        return toFormat("yyyy/MM/dd")
    }
    
    /// 本周日期范围 -> 字符串
    var curWeekRangeString: String {
        let range = curWeekRange
        if range.start.year != range.end.year {
            return range.start.toFormat("MM/dd（yyyy）") + "-" + range.end.toFormat("MM/dd（yyyy）")
        }
        let result = range.start.toFormat("MM/dd") + "-" + range.end.toFormat("MM/dd")
        if range.start.year == Date().year {
            return result
        }
        return result + "（\(range.start.year)）"
    }
    
    /// 本月日期范围 -> 字符串
    var curMonthRangeString: String {
        let range = curMonthRange
        return "\(self.year)/\(self.month.leadingZero)（\(range.start.toFormat("MM/dd"))-\(range.end.toFormat("MM/dd"))）"
    }
}
